import axios from "axios";
import { serveUrl } from "../utils/common";
const request = axios.create({
  baseURL: serveUrl,
  timeout: 10000,
})

request.interceptors.request.use(function (config) {
    if (sessionStorage.getItem("token")) {
      // 直接使用获取到的 token 字符串
      config.headers.Authorization = `Bearer ${sessionStorage.getItem("token")}`;
    }
  return config;
}, function (error) {
  return Promise.reject(error);
});

request.interceptors.response.use(
  function (response) {
    return response.data;
  },
  function (error) {
    return Promise.reject(error);
  }
)

export default request